package com.bafa.util.comparators;

import java.util.Comparator;

import com.bafa.objects.Match;
import com.bafa.objects.Score;

public class ScoreByBiggestLossComparator implements Comparator {

	public int compare(Object arg0, Object arg1) {
		Score match1 = (Score)arg0;
		Score match2 = (Score)arg1;
		
		int margin1 = match1.getGoalsAgainst()-match1.getGoalsFor();
		int margin2 = match2.getGoalsAgainst()-match2.getGoalsFor();
		
		if(margin1==margin2){
			if(match1.getGoalsAgainst()!=match2.getGoalsAgainst())
				return match2.getGoalsAgainst()-match1.getGoalsAgainst();
			if(match1.getDate().compareTo(match2.getDate())!=0)
				return match1.getDate().compareTo(match2.getDate());
			else
				return -1;
		}
		
		
		return margin2-margin1;
	}

}
